import Vue from 'vue'
import VueRouter from 'vue-router'
import System from "../views/system/System.vue"
import TenantsOverview from '../comments/tenants/TenantsOverview.vue'
import TenantsCheck from '../comments/tenants/TenantsCheck.vue'
import LessorsOverview from '../comments/lessors/LessorsOverview.vue'
import apis from "../http/apis/apis.js"

Vue.use(VueRouter)

const routes = [
    {
        path: '/system',
        name: 'System',
        component: System,
        children: [
            {
                path: '/system/tenantsOverview',
                name: 'TenantsOverview',
                component: TenantsOverview
            },
            {
                path: '/system/tenantsCheck',
                name: 'TenantsCheck',
                component: TenantsCheck
            },
            {
                path: '/system/lessorsOverview',
                name: 'LessorsOverview',
                component: LessorsOverview
            },
            {
                path: 'ParkingOverview',
                component: () => import('../comments/parkings/ParkingOverview.vue'),
            },
            {
                path: '/system/tenantsOverview',
                path: 'tenantsOverview',
                name: 'TenantsOverview',
                component: TenantsOverview
            },
            {
                path: '/system/adminsOverview',
                component: () => import('../comments/admins/AdminsOverview.vue')
            },
            {
                path: '/system/getLogs',
                name: 'GetLogs',
                component: () => import('../comments/logs/GetLogs.vue')
            },
            {
                path: 'allOrders',
                name: 'AllOrders',
                component: () => import('../comments/orders/AllOrders.vue')
            },{
                path: 'newOrders',
                name: 'NewOrders',
                component: () => import('../components/orders/NewOrders.vue')
            },
            {
                path: '/system/lessorsCheck',
                component: () => import('../comments/lessors/LessorsCheck.vue')
            },
        ],
        // 路由独享
        beforeEnter: async (to, from, next) => {
            const { data } = await apis.admins.islogin();
            if (data.type == 401) {
                alert('你还未登录，请先登录');
                next('/login')
            } else {
                next();
            }
        },
    },
    {
        path: '/login',
        name: 'Login',
        component: () => import('../views/login/Login.vue')
    },
    {
        path: '/register',
        name: 'Register',
        component: () => import('../views/register/Register.vue')
    },
    {
        path: '/Lessors',
        name: 'Lessors',
        component: () => import('../views/system/Lessors/Lessors.vue'),
        children: [
            {
                path: 'AddLessors',
                name: 'AddLessors',
                component: () => import('../comments/lessors/AddLessors.vue')
            },
            {
                path: 'LessorsList',
                name: 'LessorsList',
                component: () => import('../comments/lessors/LessorsList.vue')
            },
            {
                path: 'UpdateLessors/:_id',
                props: true,
                name: 'UpdateLessors',
                component: () => import('../comments/lessors/UpdateLessors.vue')
            },
            {
                path: 'NewOrders',
                name: 'NewOrders',
                component: () => import('../components/orders/NewOrders.vue')
            },
            // {
            //     path: 'OrdersDetails',
            //     name: 'OrdersDetails',
            //     component: () => import('../components/orders/OrdersDetails.vue')
            // }
        ],
        // 路由独享
        beforeEnter: async (to, from, next) => {
            const { data } = await apis.admins.islogin();
            if (data.type == 401) {
                alert('你还未登录，请先登录');
                next('/login')
            } else {
                next();
            }
        },
    },
    {
        // 重定向
        path: '/',
        redirect: '/system'
    }


]

const router = new VueRouter({
    routes,
    mode: 'history'//历史模式
})

export default router
